| Conditions | 2 |
| Paths | 2 |
| Total Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | 'use strict'; |
||
| 4 | MongoClient.connect('mongodb://localhost:27017/JokesApp', (err, db) => {
|
||
| 5 | if (err) {
|
||
| 6 | return console.log('error connecting to mongodb server');
|
||
|
|
|||
| 7 | } |
||
| 8 | |||
| 9 | console.log('connected to mongodb server');
|
||
| 10 | |||
| 11 | db.collection('Jokes').findOneAndUpdate({
|
||
| 12 | joke : 'Sample joke' |
||
| 13 | }, |
||
| 14 | {
|
||
| 15 | $set : {
|
||
| 16 | joke : 'This was updated joke', |
||
| 17 | likes : 1 |
||
| 18 | } |
||
| 19 | }, {
|
||
| 20 | returnOriginal : true |
||
| 21 | }).then((updatedDoc) => {
|
||
| 22 | console.log(updatedDoc); |
||
| 23 | }, (err) => {
|
||
| 24 | console.log('Error updating. E: ', err);
|
||
| 25 | }); |
||
| 26 | |||
| 27 | // display all the jokes after updating |
||
| 28 | db.collection('Jokes').find().toArray().then((docs) => {
|
||
| 29 | console.log(docs); |
||
| 30 | }, (err) => {
|
||
| 31 | console.log('error displaying all jokes. E: ', err);
|
||
| 32 | }); |
||
| 33 | //db.close(); |
||
| 34 | }); |